package com.online.teaching.module.admin.user.controller;

import com.github.pagehelper.PageInfo;
import com.online.teaching.module.admin.user.domian.dto.StudentAddDTO;
import com.online.teaching.module.admin.user.domian.dto.TeacherAddDTO;
import com.online.teaching.module.admin.user.domian.vo.StudentGetVO;
import com.online.teaching.module.admin.user.domian.vo.TeacherGetVO;
import com.online.teaching.module.admin.user.service.AdminUserService;
import com.online.teaching.pojo.Teacher;
import com.online.teaching.utils.Result;
import com.online.teaching.utils.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jdk.internal.dynalink.beans.StaticClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName : AdminUserController  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-04 13:26  //时间
 */
@Api(tags = "管理员操作用户模块")
@RestController
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;

    @Autowired
    private static final Integer id=20;

    @ApiOperation(value = "管理员添加学生", notes = "管理员添加学生")
    @PostMapping("admin/user/addStudent")
    public Result addStudent(@RequestBody StudentAddDTO studentAddDTO)
    {
        int i = adminUserService.addStudent(studentAddDTO, id);
        return i==1?new Result(true, StatusCode.OK,"添加成功"):new Result(true,StatusCode.ERROR,"添加失败");
    }


    @ApiOperation(value = "管理员添加教师", notes = "管理员添加教师")
    @PostMapping("admin/user/addTeacher")
    public Result addTeacher(@RequestBody TeacherAddDTO teacherAddDTO)
    {
        int i = adminUserService.addTeacher(teacherAddDTO, id);
        return i==1?new Result(true, StatusCode.OK,"添加成功"):new Result(true,StatusCode.ERROR,"添加失败");
    }

    @ApiOperation(value = "管理员更新用户密码", notes = "管理员更新用户密码")
    @PostMapping("admin/user/updatePassword")
    public Result updatePassword(@RequestParam @ApiParam(value = "用户id",required = true) Integer userId,@RequestParam @ApiParam(value = "用户类型1表示学生，2表示老师",required = true)Integer userType)
    {
        int i = adminUserService.updatePassword(userId,userType,id);
        return i==1?new Result(true, StatusCode.OK,"初始化密码成功"):new Result(true,StatusCode.ERROR,"初始化密码失败");
    }

    @ApiOperation(value = "管理员删除用户", notes = "管理员删除用户")
    @PostMapping("admin/user/deleteUser")
    public Result deleteUser(@RequestParam @ApiParam(value = "老师id或者学生id",required = true)Integer userId,@RequestParam @ApiParam(value = "老师id",required = true)Integer userType)
    {
        int i=adminUserService.deleteUser(userId,userType,id);
        return i==1?new Result(true, StatusCode.OK,"用户删除成功"):new Result(true,StatusCode.ERROR,"用户删除失败");
    }


    @ApiOperation(value = "管理员查询老师列表", notes = "管理员查询老师列表")
    @GetMapping("admin/user/getUserList/teacher/{page}/{size}")
    public Result<PageInfo<TeacherGetVO>> getTeacherList(@PathVariable("page")Integer page,@PathVariable("size")Integer size)
    {
        return new Result<>(true,StatusCode.OK,"查询成功",adminUserService.getTeacherList(page,size));
    }

    @ApiOperation(value = "管理员查询学生列表", notes = "管理员查询学生列表")
    @GetMapping("admin/user/getUserList/student/{page}/{size}")
    public Result<PageInfo<StudentGetVO>> getStudentList(@PathVariable("page")Integer page,@PathVariable("size")Integer size)
    {
        return new Result<>(true,StatusCode.OK,"查询成功",adminUserService.getStudentList(page,size));

    }
}
